<?php
class common
{
    public $prefix = '';

    public function __construct()
    {
        $this->prefix = 'xn_erp_';
    }

    public function get_id()
    {
        $id = pdo_getcolumn($this->_table, "1 ORDER by " . $this->_pk . " DESC", $this->_pk);
        return $id;
    }
    public function get_name_by_id($id,$field = 'name')
    {
        $name = pdo_getcolumn($this->_table, array($this->_pk => $id), $field);
        return $name;
    }
    public function count($condition)
    {
        $count = pdo_getcolumn($this->_table, $condition , "count(*)");
        return $count;
    }
    public function fetch_all($condition = array())
    {
        $return = pdo_getall($this->_table, $condition);
        return $return;
    }
    public function fetch_first($condition = array())
    {
        $return = pdo_get($this->_table, $condition);
        return $return;
    }
    public function fetch_first_by_id($id)
    {
        $return = pdo_get($this->_table, array($this->_pk => $id));
        return $return;
    }

    public function insert($array)
    {
        $return = pdo_insert($this->_table, $array);
        return $return;
    }
    public function update($array, $condition)
    {
        $return = pdo_update($this->_table, $array, $condition);
        return $return;
    }
    public function update_by_id($array, $id)
    {
        $return = $this->update($array, array($this->_pk => $id));
        return $return;
    }
}
